[ngyongjian] iP#208
Conversation
raydent30
left a comment
There was a problem hiding this comment.
Good job on your code!
Could use some reformating.
| if (input.equals("list")) { | ||
| output = "Here are the tasks in the list:" + System.lineSeparator() + Task.printTasksList(tasks); | ||
|
|
||
| } else if (input.matches("mark [0-9]{1,2}")) { | ||
| String[] marks = input.split(" "); | ||
| tasks.get(Integer.parseInt(marks[1]) - 1).markAsDone(); | ||
| output = "Nice! I've marked this task as done:" + System.lineSeparator() | ||
| + tasks.get(Integer.parseInt(marks[1]) - 1).toString(); | ||
| } else if (input.matches("unmark [0-9]{1,2}")) { | ||
| String[] marks = input.split(" "); | ||
| tasks.get(Integer.parseInt(marks[1]) - 1).markAsNotDone(); | ||
| output = "OK, I've marked this task as not done yet:" + System.lineSeparator() | ||
| + tasks.get(Integer.parseInt(marks[1]) - 1).toString(); | ||
| } else if (input.startsWith("todo", 0)) { | ||
| String toDoDesc = input.split("todo")[1].trim(); | ||
| Task toDo = new Todo(toDoDesc); | ||
| tasks.add(toDo); | ||
| output = "Got it. I've added this task:" + System.lineSeparator() | ||
| + toDo.toString() + System.lineSeparator() + "Now you have " + Task.numberOfTasks | ||
| + " in the list."; | ||
| } else if (input.startsWith("deadline", 0)) { | ||
| String deadlineDesc = input.split("/")[0].split("deadline")[1].trim(); | ||
| String deadlineDay = input.split("/")[1].trim(); | ||
| Task deadline = new Deadline(deadlineDesc, deadlineDay); | ||
| tasks.add(deadline); | ||
| output = "Got it. I've added this task:" + System.lineSeparator() | ||
| + deadline.toString() + System.lineSeparator() + "Now you have " + Task.numberOfTasks | ||
| + " in the list."; | ||
| } else if (input.startsWith("event", 0)) { | ||
| String eventDesc = input.split("/")[0].split("event")[1].trim(); | ||
| String start = input.split("/")[1].trim(); | ||
| String end = input.split("/")[2].trim(); | ||
| Task event = new Event(eventDesc, start, end); | ||
| tasks.add(event); | ||
| output = "Got it. I've added this task:" + System.lineSeparator() | ||
| + event.toString() + System.lineSeparator() + "Now you have " + Task.numberOfTasks | ||
| + " in the list."; | ||
| } else { | ||
| Task task = new Task(input); | ||
| tasks.add(task); | ||
| output = "Got it. I've added this task:" + System.lineSeparator() | ||
| + task.toString() + System.lineSeparator() + "Now you have " + Task.numberOfTasks | ||
| + " in the list."; | ||
| } |
There was a problem hiding this comment.
Good code readability with the else-if statements!
| System.out.println("What can I do for you?\n"); | ||
| ArrayList<Task> tasks = new ArrayList<Task>(); | ||
| try (Scanner scan = new Scanner(System.in)) { | ||
| String input = scan.nextLine(); |
There was a problem hiding this comment.
"Arrow Head" code, maybe you can consider avoiding deep nesting?
| + event.toString() + System.lineSeparator() + "Now you have " + Task.numberOfTasks | ||
| + " in the list."; | ||
| } else { | ||
| Task task = new Task(input); |
There was a problem hiding this comment.
A lot of complex strings/formulas, maybe consider splitting them up?
| Task event = new Event(eventDesc, start, end); | ||
| tasks.add(event); | ||
| output = "Got it. I've added this task:" + System.lineSeparator() | ||
| + event.toString() + System.lineSeparator() + "Now you have " + Task.numberOfTasks |
There was a problem hiding this comment.
A lot of "magic numbers" involved. Maybe can consider using constants instead?
There was a problem hiding this comment.
Try not to use magic numbers. Can consider using an aptly named variable.
There was a problem hiding this comment.
Can consider using switch case instead of if else to decide what to do based on the first word entered
| System.out.println("Hello from\n" + logo); | ||
| System.out.println("Hello! I'm Duke"); | ||
| System.out.println("What can I do for you?\n"); | ||
| ArrayList<Task> tasks = new ArrayList<Task>(); |
There was a problem hiding this comment.
I like how you used a resizable array to store the tasks instead of a fixed size of 100.
| System.out.println("Hello! I'm Duke"); | ||
| System.out.println("What can I do for you?\n"); | ||
| ArrayList<Task> tasks = new ArrayList<Task>(); | ||
| try (Scanner scan = new Scanner(System.in)) { |
There was a problem hiding this comment.
Please follow the Java coding standards when using exceptions.
| try (Scanner scan = new Scanner(System.in)) { | |
| try { | |
| Scanner scan = new Scanner(System.in) |
| System.out.println("___________________________________________________"); | ||
| input = scan.nextLine(); | ||
| } | ||
| } catch (NumberFormatException e) { |
| @@ -0,0 +1,15 @@ | |||
| public class Event extends Task { | |||
| protected String start; | |||
There was a problem hiding this comment.
variables such as start and end can be more descriptive.
theopin
left a comment
There was a problem hiding this comment.
Good implementation on Duke so far! Some general points to improve your code:
- Use of magic literals: Do try to identify such literals and replace them with named constants so that readers can better understand what your code aims to achieve
- Long Main method: Due to implementation of all the main features of duke being consolidated in the main function, it seems difficult to read and understand the flow of it. Do consider refacotring these features into seperate methods to enhance understandability of the code
| } else if (input.startsWith("mark")) { | ||
| String[] marks = input.split(" "); | ||
| tasks.get(Integer.parseInt(marks[1]) - 1).markAsDone(); | ||
| output = "Nice! I've marked this task as done:" + System.lineSeparator() | ||
| + tasks.get(Integer.parseInt(marks[1]) - 1).toString(); |
There was a problem hiding this comment.
Try extracting such chunks into a seperate method to ease readability of the main function as it seems to be too big currently
| String deadlineDesc = input.split("/")[0].split("deadline")[1].trim(); | ||
| String deadlineDay = input.split("/")[1].trim(); |
There was a problem hiding this comment.
Strings such as "/" and "deadline" seem to suggest usage of magic literals, do consider declaring them as named constants to enhance readability and understandability
| } else if (input.startsWith("event", 0)) { | ||
| String eventDesc = input.split("/")[0].split("event")[1].trim(); | ||
| String start = input.split("/")[1].trim(); |
There was a problem hiding this comment.
Indentation seems off here, should be 4 instead of 2
Branch level 9
add JavaDoc
No description provided.